<script setup>
import { computed, ref } from 'vue'

// const leftCount = ref(0)
const props = defineProps({
  list: {
    type: Array,
    default: () => [],
  },
  type: {
    type: String,
    default: 'all',
  },
})
const emit = defineEmits(['clranFn', 'chanegeType'])
const leftCount = computed(() => {
  return props.list.filter((item) => !item.done).length
})

const showClear = computed(() => {
  return props.list.some((item) => item.done)
})

// 改变点击的时候选择的内容
</script>

<template>
  <!-- This footer should be hidden by default and shown when there are todos -->
  <footer class="footer">
    <!-- v-if="list.length > 0" -->
    <!-- This should be `0 items left` by default -->
    <span class="todo-count"
      ><strong>{{ leftCount }}</strong> 剩余
    </span>
    <!-- Remove this if you don't implement routing -->
    <ul class="filters">
      <li>
        <a
          @click="emit('chanegeType', 'all')"
          :class="{ selected: type === 'all' }"
          href="#/all"
          >所有</a
        >
      </li>
      <li>
        <a
          @click="emit('chanegeType', 'active')"
          :class="{ selected: type === 'active' }"
          href="#/active"
          >未完成</a
        >
      </li>
      <li>
        <a
          @click="emit('chanegeType', 'completed')"
          :class="{ selected: type === 'completed' }"
          href="#/completed"
          >已经完成</a
        >
      </li>
    </ul>
    <!-- Hidden if no completed items are left ↓ -->
    <button v-if="showClear" class="clear-completed" @click="emit('clranFn')">
      清空已完成
    </button>
  </footer>
</template>
